<?php
global $wpsc_custom_meta, $wpsc_variations;

$sticky = get_option('sticky_posts');

$args = array(
    'post_type' => 'wpsc-product',
    'posts_per_page' => 9,
    'post__in' => $sticky,
    'orderby' => 'rand',
    'order' => 'DESC',
);

$featured_query = new WP_Query($args);
?>
<div id="feature_product">
    <h2><a href="#"><?php _e('Featured Products &raquo;', 'morebag') ?></a></h2>
    <ul class="thumbnails">
        <?php
        $count = 0;
        while ($featured_query->have_posts()) : $featured_query->the_post();
            $wpsc_custom_meta = new wpsc_custom_meta(get_the_ID());
            $wpsc_variations = new wpsc_variations(get_the_ID());

            if ($count % 3 == 0 && $count > 0) {

                echo '</ul><ul class="thumbnails">';
            }
            $count++;
            ?>
            <li class="span3">
                <div class="thumbnail feature-thumb">
                    <div class="product-image">
    <?php if (wpsc_the_product_thumbnail()) :
        ?>
                            <a rel="<?php echo wpsc_the_product_title(); ?>"  href="<?php echo wpsc_the_product_permalink(); ?>">
                                <img class="product_image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="<?php echo wpsc_the_product_title(); ?>" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo wpsc_the_product_thumbnail(); ?>"/>

                            </a>
    <?php else: ?>
                            <a href="<?php echo wpsc_the_product_permalink(); ?>">
                                <img class="no-image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="No Image" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo WPSC_CORE_THEME_URL; ?>wpsc-images/noimage.png" width="<?php echo get_option('product_image_width'); ?>" height="<?php echo get_option('product_image_height'); ?>" />	
                            </a>
    <?php endif; ?>
                    </div>

                    <div class="caption custom-caption">
                        <h5 class="product-title"><a href="<?php echo wpsc_the_product_permalink(); ?>"><?php echo wpsc_the_product_title(); ?></a></h5>
                        <div class="product-price">

                            <p class="pricedisplay sale-price product_<?php echo wpsc_the_product_id(); ?>"><b id='product_price_<?php echo wpsc_the_product_id(); ?>' class="currentprice pricedisplay"><?php echo wpsc_the_product_price(); ?></b></p>
                                </div><!-- .product-price -->
                            <?php if (wpsc_product_external_link(wpsc_the_product_id()) != '') : ?>
                                <?php $action = wpsc_product_external_link(wpsc_the_product_id()); ?>
                            <?php else: ?>
                                <?php $action = htmlentities(wpsc_this_page_url(), ENT_QUOTES, 'UTF-8'); ?>					
                            <?php endif; ?>	
                            <form class="product_form"  enctype="multipart/form-data" action="<?php echo $action; ?>" method="post" name="product_<?php echo wpsc_the_product_id(); ?>" id="product_<?php echo wpsc_the_product_id(); ?>" >
                            <?php do_action('wpsc_product_form_fields_begin'); ?>
                            <input type="hidden" value="add_to_cart" name="wpsc_ajax_action"/>
                            <input type="hidden" value="<?php echo wpsc_the_product_id(); ?>" name="product_id"/>
                            <div class="btn-add-cart"><button type="submit" name="Buy" class="btn wpsc_buy_button" id="product_<?php echo wpsc_the_product_id(); ?>_submit_button" title="<?php _e('Add To Cart', 'wpsc'); ?>"><i class="icon-shopping-cart"></i> <?php _e('Add To Cart', 'wpsc'); ?></button></div>
    <?php do_action('wpsc_product_form_fields_end'); ?>
                            </form><!--close product_form-->
                        
                    </div>
                </div>
            </li>
    <?php
endwhile;
?>
    </ul>

</div><!-- #feature_product -->